package cn.edu.nju.oraldefense.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.json.annotations.JSON;

import cn.edu.nju.oraldefense.model.Graduate;
import cn.edu.nju.oraldefense.model.Paper;
import cn.edu.nju.oraldefense.service.CommentService;
import cn.edu.nju.oraldefense.service.PaperService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 默认为已登录学生查询个人论文的方法
 * 
 * @author ZhangZu
 * 
 */
public class PaperInfoAction extends ActionSupport {

	private int paperId;
	private Paper paper;
	private Graduate graduate;
	private List commentList;
	// private Comment comment;
	private PaperService paperService;
	private CommentService commentService;

	public int getPaperId() {
		return paperId;
	}

	public void setPaperId(int paperId) {
		this.paperId = paperId;
	}

	public Paper getPaper() {
		return paper;
	}

	public void setPaper(Paper paper) {
		this.paper = paper;
	}

	public Graduate getGraduate() {
		return graduate;
	}

	public void setGraduate(Graduate graduate) {
		this.graduate = graduate;
	}

	public List getCommentList() {
		return commentList;
	}

	public void setCommentList(List commentList) {
		this.commentList = commentList;
	}

	@JSON(serialize = false)
	public PaperService getPaperService() {
		return paperService;
	}

	@Resource
	public void setPaperService(PaperService paperService) {
		this.paperService = paperService;
	}

	@JSON(serialize = false)
	public CommentService getCommentService() {
		return commentService;
	}

	@Resource
	public void setCommentService(CommentService commentService) {
		this.commentService = commentService;
	}

	public String graduateExecute() {
		ActionContext ctx = ActionContext.getContext();
		graduate = (Graduate) ctx.getSession().get("graduate");
		if (graduate != null) {
			paper = paperService.getByGraduate(graduate);
			System.out.println(paper);
			commentList = commentService.getByPaper(paper);
			System.out.println(commentList.size());
			graduate.setPaper(paper);
			//paper.setCommentList(commentList);
		}
		return SUCCESS;
	}

	public String teacherExecute() {
		paper = paperService.getById(paperId);
		commentList = commentService.getByPaper(paper);
		//paper.setCommentList(commentList);
		return SUCCESS;
	}

}
